Skip to content

feat(agents): reuse daily statistics for usage overviews - #251

Merged
xiaoyumuxi merged 7 commits into
Lithe-IDEA:mainfrom
WhiteZeek:feat/2594-usage-rollups
Dec 3, 2026
Merged

xiaoyumuxi merged 7 commits into
Lithe-IDEA:mainfrom
WhiteZeek:feat/2594-usage-rollups

Conversation

@WhiteZeek

@WhiteZeek WhiteZeek commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Refs 1lck/Lithe-IDEA#2594

What changes

  • Maintain the winning copy of each (agent, call key) in the session-cache write transaction, using the existing path order. A replacement or removal invalidates the days of both the old and the new winner. The v3 cache is rebuilt from session files using the existing versioned-cache lifecycle.
  • Persist finished local days by agent, model, provider and outcome. Preserve eligible cache-hit denominators, tiered pricing, coverage counts and mean first-token latency. Check the rates actually used that day before reusing its costs.
  • Keep sorted speed samples in SQLite blobs with block bounds. Calculate exact medians across days by reading candidate blocks. A single read snapshot supplies totals, the selected breakdown, and the time series. Current and partial days, hourly charts, session filters and free-text searches use exact detail reads. Concurrent indexing can invalidate publication without invalidating the answer.
  • If a cached row is malformed, scan the records again within the same snapshot and rebuild that day. A refused cache write leaves the exact result available. Report one cache diagnostic per overview. Day buckets follow the supplied offset transitions, and hour buckets use the hour anchor or UTC offset.
  • Extend only the desktop command in agents v0. Existing single-group requests and the plugin-facing agents/usage interface keep their response shapes. The four plugin SDKs do not expose this desktop command. Update the contract, catalog, changelog and shared calendar fixture.
Plan Method Purpose
API-45 agentSessions.stats Read a whole usage overview in one request.

Windows x64 verification

  • At 5a88ef8, a two-connection WAL regression reproduced SQLite 517 when an overview published after record deletion had already read its snapshot. Authoritative record changes now reserve the writer before that read. The overview still returns exact totals and yields publication. An unchanged file list takes no write lock for removals. All 53 session-store tests and affected-crate Clippy passed. The follow-up merge (2f236ab) includes Core feat(tree): 紧凑显示时模块根与标记目录自成一行 #259. The project-tree crate and its shared row fixture match the desktop main pin, and the session-store and project-tree unit suites passed on that merge.

  • At 0c390b3, all 52 session-store tests and 85 runtime tests passed on Windows x64. Regression cases cover damaged price, count and speed data, cache writes refused by SQLite, all-agent store reads, and distinct overview request errors. An empty desktop permission selection still returns no records.

  • Clippy, platform test placement, Rust comments/Rustdoc and plugin documentation checks passed.

  • Windows x64 release benchmark at 0c390b3, two runs of the checked-in harness. All comparisons with exact totals, breakdowns and time series passed. For 175,000 calls, warm reads took 23.8–42.7 ms and three exact scans took 2.79–3.82 s. For 350,000 calls, warm reads took 104.9–220.9 ms and three exact scans took 6.93–8.73 s. In a separate run of the earlier candidate binary on the same machine, warm reads took 20.4–22.5 ms and 160.4–175.4 ms respectively. These timings cover Core only.

  • Original release benchmark, synthetic 175,000 calls across 175 days. Three detail scans on the original Core took 4.97 s. The candidate took 1.10 s on first overview, 19.8–22.8 ms when warm, and 24.8 ms with 1,000 calls in the current day. Results matched the three independent projections. The benchmark excludes desktop rendering.

  • Warm overview read zero detail rows and 868,608 bytes of speed samples across all three projections. A late insert rebuilt 1,001 detail rows. With 350,000 calls, warm reads took 99.5–103.0 ms.

  • Trade-off at 175,000 calls: original synthetic ingestion was 0.85 s and the database was 13.16 MB. The candidate took 2.76 s to ingest, using 27.68 MB before rollups and 29.93 MB after rollups. Text search and changed effective prices can still read historical detail.

Desktop #2630 consumes the candidate for integration and must use a merged Core revision before release. Native macOS verification is pending.

@xiaoyumuxi xiaoyumuxi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

审了一遍。最需要处理的是缓存写入或解码失败会让整个概览读不出来,而不是回退到精确扫描(第 477、545 行);其余是错误码、契约说明和防御性的小问题,详见行内评论。

Comment thread rust/crates/agent-sessions/src/stats.rs Resolved
@WhiteZeek
WhiteZeek marked this pull request as ready for review December 3, 2026 03:33
devin-ai-integration[bot]

This comment was marked as resolved.

@xiaoyumuxi
xiaoyumuxi merged commit 080ead6 into Lithe-IDEA:main Dec 3, 2026
12 checks passed
@WhiteZeek
WhiteZeek deleted the feat/2594-usage-rollups branch December 3, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants